home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-20 | 6.0 KB | 243 lines | [TEXT/MPS ] |
- #include <Types.h>
- #include <Strings.h>
- #include <Memory.h>
- #include <QuickDraw.h>
- #include <Errors.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Printing.h>
-
- #include "THyperXCmd.h" //our custom HyperCard class library
-
- void DoPrintPS(TXCMDBlock *myParamPtr);
-
- pascal void SendPS ( TXCMDBlock *myParamPtr )
- {
-
- THPrint prRecHdl= nil;
- TPPrPort myPrPort=nil;
- TPrStatus myStRec;
- short theErr;
- CString errString;
-
- /*
- check for the correct number of HC parameters
- */
-
- if ( !myParamPtr->informArgNums((char *) "SendPS", 2) )
- return;
-
- /*
- Recover the printer record and printing grafPort from the HC globals myPrintRecord
- and myPrinterPort, respectively.
- */
-
- prRecHdl= (THPrint) myParamPtr->RecoverLongGlobal((StringPtr) "\pmyPrintRecord");
- myPrPort= (TPPrPort) myParamPtr->RecoverLongGlobal((StringPtr) "\pmyPrinterPort");
-
- /*
- If the first HC argument is true, then close the document and exit, otherwise, proceed.
- */
-
- if (myParamPtr->RecoverBooleanArg(0))
- {
- if (prRecHdl)
- {
- PrCloseDoc(myPrPort);
- if (theErr=PrError())
- {
- errString= CString((char *)"PrCloseDoc failed. ") + CString((long) theErr);
- myParamPtr->SignalFatalError(errString);
- return;
- }
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrinterPort", (long) 0);
-
- if ( (**prRecHdl).prJob.bJDocLoop == bSpoolLoop )
- PrPicFile(prRecHdl,nil,nil,nil, &myStRec);
- if (theErr=PrError())
- {
- errString= CString((char *)"PrPicFile failed. ") + CString((long) theErr);
- myParamPtr->SignalFatalError(errString);
- return;
- }
-
- PrClose();
- if (theErr=PrError())
- {
- errString= CString((char *)"PrClose failed. ") + CString((long) theErr);
- myParamPtr->SignalFatalError(errString);
- return;
- }
-
- DisposHandle((Handle) prRecHdl);
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrintRecord", nil);
- }
-
- }
- /*
- If the first parameter is false, and the print record handle is nil, create
- the handle, initialize printing, and put up the job dialog.
- */
- else if (!prRecHdl)
- {
- prRecHdl=(THPrint) NewHandle(sizeof(TPrint));
- if (!prRecHdl)
- {
- myParamPtr->SignalFatalError((char *)"Out of memory!");
- return;
- }
-
- PrOpen();
-
- if (theErr=PrError())
- {
- errString= CString((char *)"PrOpen failed. ") + CString((long) theErr);
- myParamPtr->SignalFatalError(errString);
- return;
- }
-
- if (!PrJobDialog(prRecHdl))
- {
- myParamPtr->SignalReturnStatus("\pCancel");
- PrClose();
- DisposHandle((Handle) prRecHdl);
- return;
- }
- if (theErr=PrError())
- {
- errString= CString((char *)"PrJobDialog failed. ") + CString((long) theErr);
- myParamPtr->SignalFatalError(errString);
- PrClose();
- DisposHandle((Handle) prRecHdl);
- return;
- }
-
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrintRecord", (long) prRecHdl);
-
- myPrPort = PrOpenDoc(prRecHdl,nil,nil);
- if (theErr=PrError())
- {
- if (theErr==iPrAbort)
- {
- myParamPtr->SignalReturnStatus("\pAbort");
- PrCloseDoc(myPrPort);
- }
- else
- {
- errString= CString((char *)"PrOpenDoc failed. ") + CString((long) theErr);
- myParamPtr->SignalFatalError(errString);
- }
- DisposHandle((Handle) prRecHdl);
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrintRecord", nil);
- PrClose();
- return;
- }
-
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrinterPort", (long) myPrPort);
-
- // Set globals for the first and last page from the dialog box
-
- myParamPtr->SetLongGlobal((StringPtr) "\pfirstPage", (long) (**prRecHdl).prJob.iFstPage);
- myParamPtr->SetLongGlobal((StringPtr) "\plastPage", (long) (**prRecHdl).prJob.iLstPage);
- }
- /*
- If the first parameter is false, and the print record handle is not nil, print
- the postscript text passed in the second parameter.
- */
- else
- {
- PrOpenPage(myPrPort,nil);
- if (theErr=PrError())
- {
- if (theErr==iPrAbort)
- myParamPtr->SignalReturnStatus("\pAbort");
- else
- {
- errString= CString((char *)"PrOpenPage failed. ") + CString((long) theErr);
- myParamPtr->SignalFatalError(errString);
- }
- PrCloseDoc(myPrPort);
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrinterPort", (long) 0);
- PrClose();
- DisposHandle((Handle) prRecHdl);
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrintRecord", nil);
- return;
- }
-
- DoPrintPS(myParamPtr);
-
- PrClosePage(myPrPort);
- if (theErr=PrError())
- {
- if (theErr==iPrAbort)
- myParamPtr->SignalReturnStatus("\pAbort");
- else
- {
- errString= CString((char *)"PrClosePage failed. ") + CString((long) theErr);
- myParamPtr->SignalFatalError(errString);
- }
- PrCloseDoc(myPrPort);
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrinterPort", (long) 0);
- PrClose();
- DisposHandle((Handle) prRecHdl);
- myParamPtr->SetLongGlobal((StringPtr) "\pmyPrintRecord", nil);
- return;
- }
- }
-
- myParamPtr->SignalReturnStatus("\pOK");
- return;
- }
-
- void DoPrintPS(TXCMDBlock *myParamPtr)
- {
-
- const short PostScriptBegin=190;
- const short PostScriptEnd=191;
- const short PostScriptHandle=192;
- const short PostScriptFile=193;
- const short TextIsPostScript=194;
-
- Rect textFrame;
- Handle textHandle=myParamPtr->RecoverHandleArg(1);
- register Ptr textPtr = *textHandle;
- short textLen = (short) strlen(textPtr);
-
-
- /*
- translate returns into spaces, zero term into return
- */
-
- for (short charNum=1;charNum<=textLen;charNum++)
- {
- if (*textPtr== (char)0x0D)
- *textPtr=(char)' ';
- textPtr++;
- }
- *textPtr= (char) 0x0D;
- textLen+=1;
-
- /*
- Convert the PostScript text to a Pict and print. Set the font to Helvetica so
- the driver does not get the idea that it must create a bitmap of a screen font.
- */
-
- SetRect(&textFrame,-8192,-8192,8192,8192);
- TextFont(helvetica);
- ClipRect(&textFrame);
- MoveTo(20,20);
- DrawString((const Str255) "\p "); // get around driver optimization
- PicComment(PostScriptBegin,0,nil);
-
- PicComment(TextIsPostScript,0,nil);
- DrawString((const Str255) "\pinitgraphics"); // so we have the default coordinate system
- DrawString((const Str255) "\pjeffDict begin"); // use our private dict
- PicComment(PostScriptHandle,textLen,textHandle);
- DrawString((const Str255) "\pend"); // close our dict
- PicComment(PostScriptEnd,0,nil);
- HUnlock(textHandle);
-
- return;
-
- }
-